// 新建一个队列,根节点入队
// 把队头出队并访问 2
// 把队头的children挨个入队 3
// 重复2-3,直到队列为空

const tree = {
    val: "a",
    children: [
        {
            val: "b",
            children: [{
                val: "d",
                children: []
            }, {
                val: "e",
                children: []
            }]
        },
        {
            val: "c",
            children: [{
                val: "f",
                children: []
            }, {
                val: "g",
                children: []
            }]
        }
    ]
}

const bfs = (root) => {
    const q = [root];
    while (q.length) {
        const n = q.shift();
        console.log(n.val);
        n.children.forEach((e) => {
            q.push(e)
        })
    }
}
bfs(tree)